<template>
  <uni-nav-bar title="分拨账户" left-icon="left" @clickLeft="navBack" :fixed="true" statusBar></uni-nav-bar>
  <view class="package">分拨账户：{{getFenbo.money}}</view>
  <view class="package">
    <view class="space-between top">
      <view class="center">
        <uni-icons type="circle-filled" size="20" color="#1F92FE"></uni-icons>
        <view style="margin-left: 10rpx;">郑州</view>
      </view>
      <view class="center price" @click="increase()">
        <view>分拨</view>
        <view style="margin-left: 10rpx;">{{getFenbo.price}}</view>
      </view>
    </view>
  </view>
  <!-- 填写价 -->
  <Price @submit="submit" ref="AddPrice"></Price>
</template>

<script setup lang="ts">
  import { navBack } from '@/utils/navigator';
  import { ref } from 'vue';
  import { toPublish } from '@mqtt';
  import { showLoading, errorToast } from '@/utils/prompt';
  import { information } from '@/stores/administrator';
  import Price from '@c/administrator/BulletBox/payFor.vue';
  import { getFenboInfo } from '@/gql/administrator';
  const TeamInfo = information();
  const AddPrice = ref(null)
  const getFenbo = ref({})
  init()
  function init() {
    showLoading()
    const payload = {
      query: getFenboInfo,
      variables: {
        team_id: Number(TeamInfo.teamAll.id),
      },
    };
    toPublish(
      'ql/control/getFenboInfo',
      payload,
      (obj : any) => {
        const { getFenboInfo } = obj.data;
        getFenbo.value = getFenboInfo
      }
    );
  }
  function increase() {
    AddPrice.value.openBankPad()
  }
  // 填写价
  function submit(num : number) {
    console.log(num)
    showLoading('正在提交');
    const payload = {
      id: getFenbo.value.fenbo_id,
      price: num
    };
    toPublish('control/editFenboPrice', payload, (obj : any) => {
      uni.hideLoading();
      const { code, msg } = obj;
      if (code === 1) {
        init()
      } else {
        errorToast(msg)
      }
    });
  }
</script>

<style scoped lang="less">
  .price view:nth-child(even) {
    width: 174rpx;
    height: 45rpx;
    border: 1px solid #CECECE;
    border-radius: 6rpx;
    text-align: center;
    line-height: 45rpx;
  }
</style>